<?php

/*
 * initialize.php
 *
 * Initialize core backend system
 */

// NOTE: do not include kebcore.php here, it will record the visitor in database not created yet

require_once( 'core/conf.php' );
require_once( 'core/log.php' );
require_once( 'core/util.php' );
require_once( 'core/db.php' );
require_once( 'core/locale.php' );
require_once( 'core/output.php' );
require_once( 'core/service.php' );

require_once( 'core/init.php' );

// TODO: not needed?
// set printing method
//setPrintMethod( 'RAW' );
//Output::inst()->setMode( 'HTML' );

// force reload session next time
Conf::resetSession();

?>
<html>
<head>
<title>Initialization</title>
</head>
<body>
<?php

// request fields defined in displayChoices()
if( !isset($_REQUEST['defined']) )
	displayChoices();
else
	startInitProcess();

if( isset($_REQUEST['createdb']) )
	createDatabase();

if( isset($_REQUEST['initdb']) )
	initDatabase();

if( isset($_REQUEST['initusergroup']) )
	initUserGroup();

if( isset($_REQUEST['initperms']) )
	initServicesDatabase();

if( isset($_REQUEST['initsite']) )
{
	$siteInit = '../site/init.php';
	if( file_exists($siteInit) )
	{
		require_once( $siteInit );
		// must be defined in site/init.php
		siteInitialize();
	}
}

if( isset($_REQUEST['defined']) )
{
	print( "<br>\n" );
	print( 'done.<br>'."\n" );
}

?>
</body>
</html>
